/**
 * @file NetCtrl.c
 * @Synopsis
 * @author JzeTech
 * @version 0.1 beta
 * @date 1009-08-18
 */

#include "netVideoPara.h"
extern struct devconfig *global_config;
extern int shmid_status;
extern int shmid_config;
/**
 * @brief
 *
 * @param root
 * @param mhandle
 */
#if 0
void GetFrameStruct(mxml_node_t* root, FrameStruct *frameStruct)
{
	int num = 0;
	char *tmp = NULL;
	mxml_node_t *node = NULL;
	FrameStruct *pFrameStruct = NULL;

    pFrameStruct = frameStruct;
	//node = (mxml_node_t *)HaveNode(root, "FrameStruct");
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("GetFrameStruct : No Format ELement");
		return;
    }

	num = GetNodeAttrsNum(node);
	tmp = (char *)GetNodeAttrsValue(node, "FrameRate", num);
	pFrameStruct->frameRate = atoi(tmp);

	tmp = (char *)GetNodeAttrsValue(node, "KeyFrameIntervals", num);
	pFrameStruct->keyFrameIntervals = atoi(tmp);

	return;
}

/**
 * @brief
 *
 * @param root
 * @param mhandle
 */
void GetQuantLevel(mxml_node_t* root, char* quantLevel)
{
	mxml_node_t *node = NULL;
    char *pLevel = NULL;

	pLevel = quantLevel;
	//node = (mxml_node_t *)HaveNode(root, "Quant");
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("GetQuantLevel : No Format ELement");
		return;
    }

	*pLevel = *(char *)GetNodeAttrsValue(node, "Level", 1) - '0';

	return;
}

/**
 * @brief
 *
 * @param root
 * @param mhandle
 */
void GetMaxBPS(mxml_node_t *root, char *maxBPS)
{
	mxml_node_t *node = NULL;
	char *tmp = NULL, *pmaxBPS = maxBPS;
	int val = 0;

	//node = (mxml_node_t *)HaveNode(root, "BaudRate");
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("GetMaxBPS : No Format ELement");
		return;
    }

	tmp = (char *)GetNodeAttrsValue(node, "MaxBPS", 1);
	val = atoi(tmp);
	*pmaxBPS = *((char *)&val);
	*(pmaxBPS+1) = *((char *)&val+1);

	return;
}

/**
 * @brief
 *
 * @param root
 * @param mhandle
 */
void GetPicFormat(mxml_node_t* root, PicFormat* picFormat)
{
	int num = 0;
	char* tmp = NULL;
	PicFormat *pPicFormat = NULL;
	mxml_node_t *node = NULL;

	pPicFormat = picFormat;
	//node = (mxml_node_t *)HaveNode(root, "Format");
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("GetPicFormat : No Format ELement");
		return;
    }

	num = GetNodeAttrsNum(node);
	tmp = (char *)GetNodeAttrsValue(node, "PicFormat", num);
	int val = atoi(tmp);
	pPicFormat->picfm = *(char *)(&val);

	//tmp = (char *)GetNodeAttrsValue(node, "SupportFormat", num);
	//sprintf(pPicFormat->SupportFormat, "%s", tmp);

	return;
}

/**
 * @brief
 *
 * @param root
 * @param mhandle
 */
void GetVideoAttrs(mxml_node_t* root, VideoPara* videoPara)
{
	int num = 0;
	char* tmp = NULL;
	mxml_node_t *node = NULL;
	VideoPara *pVideoPara = NULL;

	pVideoPara = videoPara;
	//node = (mxml_node_t *)HaveNode(root, "VideoPara");
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("GetVideoAttrs : No Format ELement");
		return;
    }

	num = GetNodeAttrsNum(node);
	tmp = (char *)GetNodeAttrsValue(node, "Brightness", num);
	pVideoPara->brightness = atoi(tmp);

	tmp = (char *)GetNodeAttrsValue(node, "Contrast", num);
	pVideoPara->contrast = atoi(tmp);

	tmp = (char *)GetNodeAttrsValue(node, "Saturation", num);
	pVideoPara->saturation = atoi(tmp);

	tmp = (char *)GetNodeAttrsValue(node, "Hue", num);
	pVideoPara->hue = atoi(tmp);

	return;
}


/**
 * @brief
 *
 * @param root
 * @param mhandle
 */
void GetHideZone(mxml_node_t* root, HideZone* hideZone)
{
	mxml_node_t *node = NULL, *rect_node = NULL;
	char* tmp = NULL;
	int num = 0;
	HideZone *pHideZone = NULL;

	pHideZone = hideZone;
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("GetHideZone : No Format ELement");
		return;
    }

	num = GetNodeAttrsNum(node);
	tmp = (char *)GetNodeAttrsValue(node, "bLogoing", num);
	pHideZone->bLogoing = atoi(tmp);
	tmp = (char *)GetNodeAttrsValue(node, "Num", num);
	if(NULL != tmp)
	pHideZone->maxnum = atoi(tmp);

	int i = 0;
	rect_node = (mxml_node_t *)HaveNode(root, "Rect");
	for(;i < pHideZone->maxnum; i++)
	{
		if(NULL == rect_node)
			return;
		GetRectanglePara(rect_node, &pHideZone->rect[i], 4);
		rect_node = rect_node->next;
	}

	return;
}

/**
 * @brief
 *
 * @param root
 * @param mhandle
 */
void GetRectanglePara(mxml_node_t *node, Rect* rect, int num)
{
	char* tmp = NULL;
	Rect *pRect = NULL;
	int val = 0;

	pRect = rect;
	tmp = (char *)GetNodeAttrsValue(node, "Left", num);
    val = atoi(tmp);
	pRect->left[0] = *((char *)&val);
	pRect->left[1] = *((char *)&val+1);

	tmp = (char *)GetNodeAttrsValue(node, "Top", num);
    val = atoi(tmp);
	pRect->top[0] = *((char *)&val);
	pRect->left[1] = *((char *)&val+1);

	tmp = (char *)GetNodeAttrsValue(node, "Width", num);
    val = atoi(tmp);
	pRect->width[0] = *((char *)&val);
	pRect->width[1] = *((char *)&val+1);

	tmp = (char *)GetNodeAttrsValue(node, "Height", num);
    val = atoi(tmp);
	pRect->height[0] = *((char *)&val);
	pRect->height[1] = *((char *)&val+1);

	return;
}

/**
 * @brief
 *
 * @param root
 * @param mhandle
 */
void GetTimeAndLogo(mxml_node_t *root)
{
	mxml_node_t *node = NULL;
	char* tmp = NULL;
	int num = 0, len = 0;
	TimeLogo *pTimeLogo = NULL;

	kshm_lock(shmid_config);
	pTimeLogo = &global_config->codec_param.time_logo;
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("GetTimeAndLogo : No Format ELement");
		return;
    }
	num = GetNodeAttrsNum(node);
	tmp = (char *)GetNodeAttrsValue(node, "bOSDing", num);
	pTimeLogo->bOSDing = *tmp - 0x30;

	tmp = (char *)GetNodeAttrsValue(node, "nOSDPlace", num);
	pTimeLogo->nOSDPlace = *tmp - 0x30;

	tmp = (char *)GetNodeAttrsValue(node, "nWordPlace", num);
	pTimeLogo->nWordPlace = *tmp - 0x30;
	tmp = (char *)GetNodeAttrsValue(node, "Word", num);
	len = strlen(tmp);
	if(len >= 64)
		return;
#if 0
	strncpy(word, tmp, len);
#else
	strncpy(global_config->codec_param.time_logo.word, tmp, len);
#endif
	kshm_unlock(shmid_config);
	return;
}


/**
 * @brief
 *
 * @param root
 * @param mhandle
 */
void GetPicDetect(mxml_node_t* root, PicDetect* picDetect)
{
	mxml_node_t *node = NULL, *rect_node = NULL;
	char* tmp = NULL;
	int num = 0;

	PicDetect *pPicDetect = picDetect;
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("GetPicDetect : No Format ELement");
		return;
    }
	num = GetNodeAttrsNum(node);
	tmp = (char *)GetNodeAttrsValue(node, "bDectecting", num);
	pPicDetect->bDetecting = atoi(tmp);
	tmp = (char *)GetNodeAttrsValue(node, "DetectGrade", num);
	pPicDetect->detectGrade = atoi(tmp);
	tmp = (char *)GetNodeAttrsValue(node, "Num", num);
	if(NULL != tmp)
		pPicDetect->num = atoi(tmp);

#if 0
	rect_node = (mxml_node_t *)HaveNode(root, "Rect");
	if(NULL == rect_node){
		GetRectanglePara(node, &pPicDetect->rect[0], num);
	}else
	{
		num = GetNodeAttrsNum(rect_node);
		GetRectanglePara(rect_node, &pPicDetect->rect[0], num);
		while(1)
		{
			rect_node = (mxml_node_t *)SearchSubNode(rect_node, root, "Rect");
			if(rect_node == NULL)
			  break;
			num = GetNodeAttrsNum(rect_node);
			GetRectanglePara(rect_node, &pPicDetect->rect[1], num);
		}
	}
#else
	int i = 0;
	rect_node = (mxml_node_t *)HaveNode(root, "Rect");
	for(;i < pPicDetect->num; i++)
	{
		if(NULL == rect_node)
			return;
		GetRectanglePara(rect_node, &pPicDetect->rect[i], 4);
		rect_node = rect_node->next;
	}
#endif

	return;
}

/**
 * @brief Get video Para
 *
 * @param fp
 * @param root
 * @param mhandle
 */
void SetVideoFrameStructPara(FILE* fp, Video_Param* videoParam, int fd)
{
	mxml_node_t *root = NULL;
	int sockfd = fd;
	Video_Param *pVideoParam = videoParam;

	SetVideoFrameStruct(fp, root, &pVideoParam->frameStruct);
	SendVideoParaFrameStruct(sockfd);

	return;
}

void SetVideoStreamType(FILE* fp, mxml_node_t* root, MegaEyesHandle* mhandle)
{
	mxml_node_t *node = NULL, *troot = NULL;
  	char	*str = NULL;

	troot = root;
	str = "Normal";
	node = (mxml_node_t *)HaveNode(troot, "Message");
	if(NULL == node)
    {
        LOGINFO("SetVideoStreamType : No Format ELement");
		return;
    }
	SetNodeAttrValue(node, "Stream", str);
	return;
}

void SetVideoFrameStruct(FILE* fp, mxml_node_t* root, FrameStruct* frameStruct)
{
	mxml_node_t *node = NULL, *troot = NULL;
	FrameStruct *pFrameStruct = NULL;
	char str[2] = {0}, str2[3] = {0};

	troot = root;
	pFrameStruct = frameStruct;
	node = (mxml_node_t *)HaveNode(troot, "FrameStruct");
	if(NULL == node)
    {
        LOGINFO("SetVideoFrameStruct : No Format ELement");
		return;
    }

	itoa(pFrameStruct->frameRate, str, 2);
	SetNodeAttrValue(node, "FrameRate", str);

	itoa(pFrameStruct->keyFrameIntervals, str2, 2);
	SetNodeAttrValue(node, "KeyFrameIntervals", str2);

	return;
}

#endif
#if 0
void GetVideoQuantLevel(FILE* fp, mxml_node_t* root, int* level)
{
	mxml_node_t *node = NULL, *troot = NULL;
	char str[2] = {0};
	int *pLevel = NULL;

	troot = root;
	pLevel = level;
	node = (mxml_node_t *)HaveNode(troot, "Quant");
	if(NULL == node)
    {
        LOGINFO("GetVideoQuantLevel : No Format ELement");
		return;
    }

	itoa(*pLevel, str, 2);
	SetNodeAttrValue(node, "Level", str);

	return;
}

void GetVideoMaxBPS(FILE* fp, mxml_node_t* root, int* maxBPS)
{
	mxml_node_t *node = NULL, *troot = NULL;
	char str[32] = {0};
	int *pMaxBPS = NULL;

	troot = root;
	pMaxBPS = maxBPS;

	node = (mxml_node_t *)HaveNode(troot, "BaudRate");
	if(NULL == node)
    {
        LOGINFO("GetVideoPicFormat : No Format ELement");
		return;
    }

	itoa(*pMaxBPS, str, 32);
	SetNodeAttrValue(node, "MaxBPS", str);

	return;
}

void GetVideoPicFormat(FILE* fp, mxml_node_t* root, PicFormat* picFormat)
{
	mxml_node_t *node = NULL, *troot = NULL;
	char str[2] = {0}, supportFormat[13] = {0};
	PicFormat* pPicFormat = NULL;

	troot = root;
	pPicFormat = picFormat;
	node = (mxml_node_t *)HaveNode(root, "Format");
	if(NULL == node)
    {
        LOGINFO("GetVideoPicFormat : No Format ELement");
		return;
    }
	itoa(pPicFormat->picfm, str, 2);
	SetNodeAttrValue(node, "PicFormat", str);

	sprintf(supportFormat, "%s", pPicFormat->SupportFormat);
	SetNodeAttrValue(node, "SupportFormat", supportFormat);

	return;
}
#endif
/* --------------------------------------------------------------------------*/
/**
 * @Synopsis
 *
 * @Param fp
 * @Param root
 * @Param quantLevel
 */
/* ----------------------------------------------------------------------------*/
#if  0
void SetVideoQuantLevelPara(FILE *fp, int *quantLevel, int fd)
{
	mxml_node_t *node = NULL, *root = NULL;
	char str[2] = {0};
	int sockfd = 0;
	int *pQuantLevel = NULL;

	sockfd = fd;
	pQuantLevel = quantLevel;
	root = (mxml_node_t *)ParseXMLFile(fp);

	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("GetVideoPicFormat : No Format ELement");
		return;
    }

	itoa(*pQuantLevel, str, 2);
	SetNodeAttrValue(node, "Level", str);
	SendVideoParaRecordLevel(sockfd);
	return;
}

/**
 * @brief
 *
 * @param fp
 * @param root
 * @param mhandle
 */
void SetVideoMaxBPSPara(FILE* fp, int* maxBPS, int fd)
{
	mxml_node_t *node = NULL, *root = NULL;
	char str[5] = {0};
	int sockfd = 0;
	int *pMaxBPS = NULL;

	sockfd = fd;
	pMaxBPS = maxBPS;
	root = (mxml_node_t *)ParseXMLFile(fp);
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("SetVideoMaxBPSPara : No Format ELement");
		return;
    }

	itoa(*pMaxBPS, str, 5);
	SetNodeAttrValue(node, "MaxBPS", str);

	SendVideoParaMaxBPS(sockfd);
	return;
}

/**
 * @brief
 *
 * @param fp
 * @param root
 * @param mhandle
 */
void SetVideoPicFormatPara(FILE* fp, PicFormat* picFormat, int fd)
{
	mxml_node_t *node = NULL, *root = NULL;
	int sockfd = 0;
	char str[2] = {0}, supportFormat[32] = {0};
	PicFormat *pPicFormat = NULL;

	sockfd = fd;
	pPicFormat = picFormat;
	root = (mxml_node_t *)ParseXMLFile(fp);
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("SetVideoPicFormatPara : No Format ELement");
		return;
    }

	itoa(pPicFormat->picfm, str, 2);
	SetNodeAttrValue(node, "PicFormat", str);

	//sprintf(supportFormat, "%s", pPicFormat->SupportFormat);
	//SetNodeAttrValue(node, "SupportFormat", supportFormat);

	SendVideoParaPicFormat(sockfd);
	return;
}

/**
 * @brief
 *
 * @param fp
 * @param root
 * @param mhandle
 */
void SetVideoHideZonePara(FILE* fp, struct Hide_Zone* hideZone, int fd)
{
	struct Hide_Zone *pHideZone = NULL;
	mxml_node_t *node = NULL, *root = NULL, *rect_node = NULL;
	char	str[2] = {0}, str2[2] = {0};
	int		sockfd = 0;

	pHideZone = hideZone;
	sockfd = fd;
	root = (mxml_node_t *)ParseXMLFile(fp);
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("SetVideoHideZonePara : No Format ELement");
		return;
    }

	itoa(pHideZone->bLogoing, str, 2);
	SetNodeAttrValue(node, "bLogoing", str);
	itoa(pHideZone->maxnum, str2, 2);
	SetNodeAttrValue(node, "Num", str2);

	rect_node = (mxml_node_t *)HaveNode(root, "Rect");
	if(NULL == rect_node)
	{
        SetRectanglePara(node, &pHideZone->rect[0]);
	}else
	{
        SetRectanglePara(rect_node, &pHideZone->rect[0]);
		while(1)
		{
			rect_node = (mxml_node_t *)SearchSubNode(rect_node, root, "Rect");
			if(rect_node == NULL)
			  break;
            SetRectanglePara(rect_node, &pHideZone->rect[1]);
		}
	}

	SendVideoParaHideZone(sockfd);
	return;
}

/**
 * @brief
 *
 * @param fp
 * @param root
 * @param mhandle
 */
void SetVideoTimeLogoPara(FILE *fp, struct Time_Logo *timeLogo, int fd)
{
    char bOSDing[1] = {0}, nOSDPlace[1] = {0},
         nWordPlace[1] = {0};
    mxml_node_t *node = NULL, *root = NULL;
    struct Time_Logo* pTimeLogo = NULL;
    int	sockfd = 0;

    sockfd = fd;
	pTimeLogo = timeLogo;
	root = (mxml_node_t *)ParseXMLFile(fp);
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("SetVideoTimeLogoPara : No Format ELement");
		return;
    }

    itoa(pTimeLogo->bOSDing, bOSDing, 1);
	SetNodeAttrValue(node, "bOSDing", bOSDing);

    itoa(pTimeLogo->nOSDPlace, nOSDPlace, 1);
	SetNodeAttrValue(node, "nOSDPlace", nOSDPlace);

    itoa(pTimeLogo->nWordPlace, nWordPlace, 1);
	SetNodeAttrValue(node, "nWordPlace", nWordPlace);

	SetNodeAttrValue(node, "Word", pTimeLogo->word);

	SendVideoParaTimeLogo(sockfd);
	return;
}

#endif

void SendVideoParaFrameStruct(int fd)
{
	int sockfd = fd, len = 0;
	char buffer[256], *pos = NULL;
	VSP_RECVHEADER hdr;

	pos = buffer + sizeof(hdr);
    pos = memcpy(pos, XMLHEADER, strlen(XMLHEADER));
	pos += strlen(XMLHEADER);
    pos = memcpy(pos, START_MESSAGE, strlen(START_MESSAGE));
	pos += strlen(START_MESSAGE);
	len = strlen("<Para>1</Para>\n");
	pos = memcpy(pos, "<Para>1</Para>\n", len);
	pos += len;
	sprintf(pos, "<Record FrameRate=\"%d\" KeyFrameIntervals=\"%d\" />\n",
		   global_config->dev_codec_param.codec_param[0].main_vp.frameStruct.frameRate,
		   global_config->dev_codec_param.codec_param[0].main_vp.frameStruct.keyFrameIntervals);
	printf("pos %s \n",pos);
#if 0
	pos += strlen("<Record FrameRate=\"\" KeyFrameIntervals=\"\" />\n") + sizeof(char)*3;
#else
	pos += strlen(pos);
#endif
    pos = memcpy(pos, END_MESSAGE, strlen(END_MESSAGE));
    pos += strlen(END_MESSAGE);

	len = pos - buffer;
    hdr = InitVSP_RECVHeader(len - sizeof(hdr), VIDEO_PARA_GETTING_RES, 0, 0);
    memcpy(buffer, &hdr, sizeof(hdr));
    if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
    {
	    LOGERROR("SendDataFunc error!\n");
    }
    else
    	{
    	LOGINFO("send suc\n");
    	}

	return;
}


#if 0
/**
 * @brief
 *
 * @param fp
 * @param root
 * @param mhandle
 */
void SetVideoDetectingPara(FILE* fp, struct Picture_Detect* picDetect, int fd)
{
	struct Picture_Detect* pPicDet = NULL;
	mxml_node_t *node = NULL, *root = NULL, *rect_node = NULL;
	char	bDectecting[1] = {0}, bDetectGrade[1] = {0}, arrNum[1] = {0};
	int		sockfd = 0;

	pPicDet = picDetect;
	sockfd = fd;
	root = (mxml_node_t *)ParseXMLFile(fp);
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("SetVideoDetectingPara : No Format ELement");
		return;
    }

    itoa(pPicDet->bDetecting, bDectecting, 1);
	SetNodeAttrValue(node, "bDectecting", bDectecting);

    itoa(pPicDet->detectGrade, bDetectGrade, 1);
	SetNodeAttrValue(node, "DetectGrade", bDetectGrade);

    itoa(pPicDet->num, arrNum, 1);
	SetNodeAttrValue(node, "Num", arrNum);

	rect_node = (mxml_node_t *)HaveNode(root, "Rect");

	if(NULL == rect_node)
	{
        SetRectanglePara(node, &pPicDet->rect[0]);
	}else
	{
        SetRectanglePara(rect_node, &pPicDet->rect[0]);
		while(1)
		{
			rect_node = (mxml_node_t *)SearchSubNode(rect_node, root, "Rect");
			if(NULL == rect_node)
			  break;
            SetRectanglePara(rect_node, &pPicDet->rect[1]);
		}
	}
	SendVideoParaPicDetect(sockfd);
	return;
}

#endif
#if 0
void GetVideoRectPara(FILE* fp, mxml_node_t* root, struct Rectangle* rectangle)
{
	struct	Rectangle* rect = NULL;
	char*	tmp = NULL;
	char	str[128] = {0};
	int		num = 0;

	mxml_node_t *node = NULL;
	rect = rectangle;
	node = (mxml_node_t *)HaveNode(root, "Rect");
	if(NULL == node)   return;

	tmp = (char *)GetNodeAttrsValue(node, "Left", num);
	sprintf(str, "%d", (rect->left[0] | (rect->left[1]<<8)));
	strncpy(tmp, (const char *)str, strlen((const char *)str));

	tmp = (char *)GetNodeAttrsValue(node, "Top", num);
	sprintf(str, "%d", (rect->top[0] | (rect->top[1]<<8)));
	strncpy(tmp, (const char *)str, strlen((const char *)str));

	tmp = (char *)GetNodeAttrsValue(node, "Width", num);
	sprintf(str, "%d", (rect->width[0] | (rect->width[1]<<8)));
	strncpy(tmp, (const char *)str, strlen((const char *)str));

	tmp = (char *)GetNodeAttrsValue(node, "Height", num);
	sprintf(str, "%d", (rect->height[0] | (rect->height[1]<<8)));
	strncpy(tmp, (const char *)str, strlen((const char *)str));

	return;
}
#endif
#if 0
void SetVideoAttrs(FILE* fp, struct Video_Para* videoPara, int fd)
{
	mxml_node_t *node = NULL, *root = NULL;
	char brightness[3] = {0}, contrast[3] = {0}, saturation[3] = {0}, hue[3] = {0};
	struct Video_Para *pVideoPara = NULL;
	int sockfd = 0;

	root = (mxml_node_t *)ParseXMLFile(fp);
	pVideoPara = videoPara;
	sockfd = fd;
	node = (mxml_node_t *)HaveNode(root, "Record");
	if(NULL == node)
    {
        LOGINFO("SetVideoAttrs : No Format ELement");
		return;
    }

	itoa(pVideoPara->brightness, brightness, 3);
	SetNodeAttrValue(node, "Brightness", brightness);

	itoa(pVideoPara->contrast, contrast, 3);
	SetNodeAttrValue(node, "Contrast", contrast);

	itoa(pVideoPara->saturation, saturation, 3);
	SetNodeAttrValue(node, "Saturation", saturation);

	itoa(pVideoPara->hue, hue, 3);
	SetNodeAttrValue(node, "Hue", hue);

	SendVideoParaVPara(sockfd);

	return;
}

void SetRectanglePara(mxml_node_t *node, Rect* rect)
{
    mxml_node_t *pnode = NULL;
    Rect *pRect = NULL;
    char left[5] = {0}, width[5] = {0}, top[5] = {0}, height[5] = {0};

    pnode = node;
    pRect = rect;
	sprintf(left, "%d", (pRect->left[0]|(pRect->left[1]<<8)));
	SetNodeAttrValue(pnode, "Left", left);

	sprintf(left, "%d", (pRect->top[0]|(pRect->top[1]<<8)));
	SetNodeAttrValue(pnode, "Top", top);

	sprintf(left, "%d", (pRect->width[0]|(pRect->width[1]<<8)));
	SetNodeAttrValue(pnode, "Width", width);

	sprintf(left, "%d", (pRect->height[0]|(pRect->height[1]<<8)));
	SetNodeAttrValue(pnode, "Height", height);

    return;
}


#endif

void SetCapturePara(int fd, char *buff, int blen, int code)
{
    char buffer[LOCAL_HDR_LEN+1] = {0};
	int len = blen - LOCAL_HDR_LEN, hdrlen = LOCAL_HDR_LEN,
		sockfd = fd;

	LOGINFO(" channels:%d \n",buff[LOCAL_HDR_LEN]);
	LOGINFO(" channels  len :%d \n",len);
	LOGINFO(" channels:%d \n",buff[LOCAL_HDR_LEN+1]);
	LOGINFO(" channels:%d \n",buff[LOCAL_HDR_LEN+2]);



	SendIpcMsg(buff+LOCAL_HDR_LEN, len, MSGID_NET,
			  MSGID_AV, MSG_CAPTURE_CONF);

	buffer[0] = 0xFF;
	buffer[1] = 0xFF;
	buffer[2] = 0xFF;
	buffer[3] = 0xFF;
	buffer[5] = *(char *)&hdrlen;
	buffer[6] = *((char *)&hdrlen + 1);
	buffer[31] = *(char *)&code;
	buffer[32] = *((char *)(&code) + 1);
	buffer[33]=buff[LOCAL_HDR_LEN];
    if(SendDataFunc(buffer, (LOCAL_HDR_LEN+1), (LOCAL_HDR_LEN+1),
				   NULL, sockfd) == -1)
    {
        LOGERROR("SendAlarmMsg : SendDataFunc Error!\n");
	}

	return;
}

void SendCapturePara(int fd,char *buff, int blen,  int code)
{
	int sockfd = fd;
	//int channels=0;
	int len = LOCAL_HDR_LEN +1+ sizeof(vCapture_Param);
	char *buffer = (char *)malloc(len * sizeof(char));
	char *pos = buffer + LOCAL_HDR_LEN;


	//LOGINFO(" blen: %d   , channels:%d \n",blen-LOCAL_HDR_LEN,buff[LOCAL_HDR_LEN]);
	//LOGINFO(" data: 0x%x   , data:0x%x \n",buff[LOCAL_HDR_LEN-2],buff[LOCAL_HDR_LEN-1]);


	//char *pos = buffer + LOCAL_HDR_LEN, *pPos = NULL;

	*pos=0;
	//memcpy((pos+1),global_config->dev_codec_param.codec_param[0].vcapture_param, sizeof(vCapture_Param));
	*(pos+1)=global_config->dev_codec_param.codec_param[0].vcapture_param.bright;
	*(pos+2)=global_config->dev_codec_param.codec_param[0].vcapture_param.contrast;
	*(pos+3)=global_config->dev_codec_param.codec_param[0].vcapture_param.saturation;
	*(pos+4)=global_config->dev_codec_param.codec_param[0].vcapture_param.hue;
	InitLocalProHdr(buffer, code, len);
	if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
	{
		LOGERROR("SendDataFunc Error!\n");
	}

	free(buffer);
	return;
}



void SetCodecPara(int fd, char *buff, int blen, int code)
{
    char buffer[LOCAL_HDR_LEN] = {0};
	int len = blen - LOCAL_HDR_LEN, hdrlen = LOCAL_HDR_LEN,
		sockfd = fd;

	LOGINFO(" channels:%d \n",buff[LOCAL_HDR_LEN+ 11]);

	SendIpcMsg(buff+LOCAL_HDR_LEN, len, MSGID_NET,
			  MSGID_AV, MSG_CODEC_CONF);

	buffer[0] = 0xFF;
	buffer[1] = 0xFF;
	buffer[2] = 0xFF;
	buffer[3] = 0xFF;
	buffer[5] = *(char *)&hdrlen;
	buffer[6] = *((char *)&hdrlen + 1);
	buffer[31] = *(char *)&code;
	buffer[32] = *((char *)(&code) + 1);
    if(SendDataFunc(buffer, LOCAL_HDR_LEN, LOCAL_HDR_LEN,
				   NULL, sockfd) == -1)
    {
        LOGERROR("SendAlarmMsg : SendDataFunc Error!\n");
	}

	return;
}

void SendCodecPara(int fd,char *buff, int blen,  int code)
{
	int sockfd = fd, chID = 11;
	int channels=0;
	int len = LOCAL_HDR_LEN + sizeof(Codec_Param);
	char *buffer = (char *)malloc(len * sizeof(char));
	char *pos = buffer + LOCAL_HDR_LEN + chID;

	LOGINFO(" blen: %d   , channels:%d \n",blen-LOCAL_HDR_LEN,buff[LOCAL_HDR_LEN]);
	LOGINFO(" data: 0x%x   , data:0x%x \n",buff[LOCAL_HDR_LEN-2],buff[LOCAL_HDR_LEN-1]);

	if((buff[LOCAL_HDR_LEN]<0)||(buff[LOCAL_HDR_LEN]>3))
		{
		close(fd);
		free(buffer);
		return;
		}
	channels=buff[LOCAL_HDR_LEN];
	LOGINFO(" channels:%d \n",channels);
	int i=channels;
	memset(buffer, 0, len);
	len = sizeof(global_config->dev_codec_param.codec_param[i].channelName);
	*pos = global_config->dev_codec_param.codec_param[i].channels;
	pos += 1;
	//memcpy(pos, global_config->codec_param.channelName, len);
	snprintf(pos, 33, "%s", global_config->dev_codec_param.codec_param[i].channelName);
        LOGINFO("channelName: %s\n", global_config->dev_codec_param.codec_param[i].channelName);
	pos += 32;
	*pos = global_config->dev_codec_param.codec_param[i].tmTittle.isTime;
	*(++pos) = global_config->dev_codec_param.codec_param[i].tmTittle.osd_vis;
	*(++pos) = global_config->dev_codec_param.codec_param[i].chTittle.isTime;
	*(++pos) = global_config->dev_codec_param.codec_param[i].chTittle.osd_vis;
	*(++pos) = global_config->dev_codec_param.codec_param[i].codecmod;
	*(++pos) = 0x00;

	//Main
	*(++pos) = 0xFF;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.isVideo;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.picFormat.picfm;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.streamOption;
	pos += 2;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.maxBPS[0];
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.maxBPS[1];
	pos += 2 + 2;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.quantityLevel;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.frameStruct.frameRate;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.frameStruct.keyFrameIntervals;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.vPara.brightness;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.vPara.hue;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.vPara.contrast;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.vPara.saturation;
	*(++pos) = global_config->dev_codec_param.codec_param[i].main_vp.isAudio;
	*(++pos) = 0x00; //audio codec

	//Second
	*(++pos) = 0xFF;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.isVideo;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.picFormat.picfm;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.streamOption;
	pos += 2;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.maxBPS[0];
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.maxBPS[1];
	pos += 2 + 2;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.quantityLevel;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.frameStruct.frameRate;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.frameStruct.keyFrameIntervals;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.vPara.brightness;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.vPara.hue;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.vPara.contrast;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.vPara.saturation;
	*(++pos) = global_config->dev_codec_param.codec_param[i].sec_vp.isAudio;
	*(++pos) = 0x11; //audio codec

	//HideZone
	*(++pos) = global_config->dev_codec_param.codec_param[i].hideZone.bLogoing;
	*(++pos) = global_config->dev_codec_param.codec_param[i].hideZone.maxnum;
	memcpy(++pos, &global_config->dev_codec_param.codec_param[i].hideZone.rect[0], sizeof(char)*8*4*2);
	pos += sizeof(char)*8*4*2;

	//WaterMark
	*(pos) = global_config->dev_codec_param.codec_param[i].waterMark.isWaterMark;
	*(++pos) = global_config->dev_codec_param.codec_param[i].waterMark.wmbps;
	*(++pos) = global_config->dev_codec_param.codec_param[i].waterMark.wmethod;
	*(++pos) = global_config->dev_codec_param.codec_param[i].waterMark.wmlen;
	memcpy(++pos, &global_config->dev_codec_param.codec_param[i].waterMark.wmch[0],
		   sizeof(global_config->dev_codec_param.codec_param[i].waterMark.wmch));
	pos += sizeof(global_config->dev_codec_param.codec_param[i].waterMark.wmch);

	len = pos - buffer;
	InitLocalProHdr(buffer, code, len);
    if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
    {
	    LOGERROR("SendDataFunc error!\n");
    }

	free(buffer);

	return;
}

void SendVideoParaRecordLevel(int fd)
{
	int sockfd = fd, len = 0;
	char buffer[128], *pos = NULL;
	VSP_RECVHEADER hdr;

	pos = buffer + sizeof(hdr);
    pos = memcpy(pos, XMLHEADER, strlen(XMLHEADER));
	pos += strlen(XMLHEADER);
    pos = memcpy(pos, START_MESSAGE, strlen(START_MESSAGE));
	pos += strlen(START_MESSAGE);
	len = strlen("<Para>2</Para>\n");
	pos = memcpy(pos, "<Para>2</Para>\n", len);
	pos += len;
	sprintf(pos, "<Record Level=\"%d\" />\n",
		   global_config->dev_codec_param.codec_param[0].main_vp.quantityLevel);
#if 0
	pos += strlen("<Record Level=\"\" />\n") + sizeof(char);
#else
	pos += strlen(pos);
#endif
	LOGINFO("QuantLevel   :     %c\n", global_config->dev_codec_param.codec_param[0].main_vp.quantityLevel);
    pos = memcpy(pos, END_MESSAGE, strlen(END_MESSAGE));
	pos += strlen(END_MESSAGE);

    len = pos - buffer;
    hdr = InitVSP_RECVHeader(len-sizeof(hdr), VIDEO_PARA_GETTING_RES, 0, 0);
    memcpy(buffer, &hdr, sizeof(hdr));
    if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
    {
	    LOGERROR("SendDataFunc error!\n");
    }
	return;
}



void SendVideoParaMaxBPS(int fd)
{
	int sockfd = fd, len = 0;
	char buffer[128], *pos = NULL;
	VSP_RECVHEADER hdr;

	pos = buffer + sizeof(hdr);
    pos = memcpy(pos, XMLHEADER, strlen(XMLHEADER));
	pos += strlen(XMLHEADER);
    pos = memcpy(pos, START_MESSAGE, strlen(START_MESSAGE));
	pos += strlen(START_MESSAGE);
	len = strlen("<Para>3</Para>\n");
	pos = memcpy(pos, "<Para>3</Para>\n", len);
	pos += len;
	sprintf(pos, "<Record MaxBPS=\"%d\" />\n",
		    (global_config->dev_codec_param.codec_param[0].main_vp.maxBPS[0]|
		     global_config->dev_codec_param.codec_param[0].main_vp.maxBPS[1]<<8));
#if 0
	pos += strlen("<Record MaxBPS=\"\" />\n") + sizeof(char)*2;
#else
	pos += strlen(pos);
#endif
    pos = memcpy(pos, END_MESSAGE, strlen(END_MESSAGE));
	pos += strlen(END_MESSAGE);

    len = pos - buffer;
    hdr = InitVSP_RECVHeader(len-sizeof(hdr), VIDEO_PARA_GETTING_RES, 0, 0);
    memcpy(buffer, &hdr, sizeof(hdr));
    if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
    {
	    LOGERROR("SendDataFunc error!\n");
    }
	return;
}



void SendVideoParaPicFormat(int fd)
{
	int sockfd = fd, len = 0;
	char buffer[256], *pos = NULL;
	VSP_RECVHEADER hdr;

	pos = buffer + sizeof(hdr);
    pos = memcpy(pos, XMLHEADER, strlen(XMLHEADER));
	pos += strlen(XMLHEADER);
    pos = memcpy(pos, START_MESSAGE, strlen(START_MESSAGE));
	pos += strlen(START_MESSAGE);
	len = strlen("<Para>4</Para>\n");
	pos = memcpy(pos, "<Para>4</Para>\n", len);
	pos += len;
	sprintf(pos, "<Record PicFormat=\"%d\" SupportFormat=\"%s\" />\n",
		   global_config->dev_codec_param.codec_param[0].main_vp.picFormat.picfm,
		   global_config->dev_codec_param.codec_param[0].main_vp.picFormat.SupportFormat);
#if 0
	pos += strlen("<Record PicFormat=\"\" SupportFormat=\"\" />\n") +
		   strlen(global_config->codec_param.main_vp.picFormat.SupportFormat) +
		   sizeof(char);
#else
	pos += strlen(pos);
#endif
    pos = memcpy(pos, END_MESSAGE, strlen(END_MESSAGE));
	pos += strlen(END_MESSAGE);

	len = pos-buffer;
    hdr = InitVSP_RECVHeader(len - sizeof(hdr), VIDEO_PARA_GETTING_RES, 0, 0);
    memcpy(buffer, &hdr, sizeof(hdr));
    if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
    {
	    LOGERROR("SendDataFunc error!\n");
    }
	return;
}

void SendVideoParaHideZone(int fd)
{
	int sockfd = fd, len = 0, num = 0, i = 0;
	char buffer[512], *pos = NULL;
	VSP_RECVHEADER hdr;

	pos = buffer + sizeof(hdr);
    pos = memcpy(pos, XMLHEADER, strlen(XMLHEADER));
	pos += strlen(XMLHEADER);
    pos = memcpy(pos, START_MESSAGE, strlen(START_MESSAGE));
	pos += strlen(START_MESSAGE);
	len = strlen("<Para>5</Para>\n");
	pos = memcpy(pos, "<Para>5</Para>\n", len);
	pos += len;
    num = global_config->dev_codec_param.codec_param[0].hideZone.maxnum;
	sprintf(pos, "<Record bLogoing=\"%d\" Num=\"%d\" >\n",
		   global_config->dev_codec_param.codec_param[0].hideZone.bLogoing , num);
#if 0
	pos += strlen("<Record PicFormat=\"\" SupportFormat=\"\" />\n") + sizeof(char)*6;
#else
	pos += strlen(pos);
#endif
    for(;i < num; i++)
	{
        sprintf(pos, "<Rect Left=\"%d\" Top=\"%d\" Width=\"%d\" Height=\"%d\" />\n",
			   (global_config->dev_codec_param.codec_param[0].hideZone.rect[i].left[0] |
				(global_config->dev_codec_param.codec_param[0].hideZone.rect[i].left[1]<<8)),
			   (global_config->dev_codec_param.codec_param[0].hideZone.rect[i].top[0] |
				(global_config->dev_codec_param.codec_param[0].hideZone.rect[i].top[1]<<8)),
			   (global_config->dev_codec_param.codec_param[0].hideZone.rect[i].width[0] |
				(global_config->dev_codec_param.codec_param[0].hideZone.rect[i].width[1]<<8)),
			   (global_config->dev_codec_param.codec_param[0].hideZone.rect[i].height[0] |
				(global_config->dev_codec_param.codec_param[0].hideZone.rect[i].height[1]<<8)));
#if 0
		pos += strlen("<Rect Left=\"\" Top=\"\" Width=\"\" Height=\"\" />\n") +
			   sizeof(char)*4;
#else
		pos += strlen(pos);
#endif
	}
	pos = memcpy(pos, "</Record>\n", strlen("</Record>\n"));
	pos += strlen("</Record>\n");
    pos = memcpy(pos, END_MESSAGE, strlen(END_MESSAGE));
	pos += strlen(END_MESSAGE);

    len = pos - buffer;
    hdr = InitVSP_RECVHeader(len-sizeof(hdr), VIDEO_PARA_GETTING_RES, 0, 0);
    memcpy(buffer, &hdr, sizeof(hdr));
    if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
    {
	    LOGERROR("SendDataFunc error!\n");
    }
	return;
}



void SendVideoParaTimeLogo(int fd)
{
	int sockfd = fd, len = 0;
	char buffer[256], *pos = NULL;
	VSP_RECVHEADER hdr;

	pos = buffer + sizeof(hdr);
    pos = memcpy(pos, XMLHEADER, strlen(XMLHEADER));
	pos += strlen(XMLHEADER);
    pos = memcpy(pos, START_MESSAGE, strlen(START_MESSAGE));
	pos += strlen(START_MESSAGE);
	len = strlen("<Para>6</Para>\n");
	pos = memcpy(pos, "<Para>6</Para>\n", len);
	pos += len;
	sprintf(pos, "<Record bOSDing=\"%d\" nOSDPlace=\"%d\" nWordPlace=\"%d\" Word=\"%s\" />\n",
		   global_config->dev_codec_param.codec_param[0].time_logo.bOSDing,
		   global_config->dev_codec_param.codec_param[0].time_logo.nOSDPlace,
		   global_config->dev_codec_param.codec_param[0].time_logo.nWordPlace,
		   global_config->dev_codec_param.codec_param[0].time_logo.word);
	printf(" pos :%s \n",pos);
#if 0
	pos += strlen("<Record bOSDing=\"\" nOSDPlace=\"\" nWordPlace=\"\" Word=\"\" />\n") +
		   sizeof(char)*3 + strlen(global_config->codec_param.time_logo.word);
#else
	pos += strlen(pos);
#endif
    pos = memcpy(pos, END_MESSAGE, strlen(END_MESSAGE));
	pos += strlen(END_MESSAGE);

    len = pos - buffer;
    hdr = InitVSP_RECVHeader(len - sizeof(hdr), VIDEO_PARA_GETTING_RES, 0, 0);
    memcpy(buffer, &hdr, sizeof(hdr));
    if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
    {
	    LOGERROR("SendDataFunc error!\n");
    }
	return;
}



void SendVideoParaVPara(int fd)
{
	int sockfd = fd, len = 0;
	char buffer[256], *pos = NULL;
	VSP_RECVHEADER hdr;

	pos = buffer + sizeof(hdr);
    pos = memcpy(pos, XMLHEADER, strlen(XMLHEADER));
	pos += strlen(XMLHEADER);
    pos = memcpy(pos, START_MESSAGE, strlen(START_MESSAGE));
	pos += strlen(START_MESSAGE);
	len = strlen("<Para>7</Para>\n");
	pos = memcpy(pos, "<Para>7</Para>\n", len);
	pos += len;
	sprintf(pos, "<Record Brightness=\"%d\" Contrast=\"%d\" Saturation=\"%d\" Hue=\"%d\" />\n",
		   global_config->dev_codec_param.codec_param[0].main_vp.vPara.brightness,
		   global_config->dev_codec_param.codec_param[0].main_vp.vPara.contrast,
		   global_config->dev_codec_param.codec_param[0].main_vp.vPara.saturation,
		   global_config->dev_codec_param.codec_param[0].main_vp.vPara.hue);
#if 0
	pos += strlen("<Record Brightness=\"\" Contrast=\"\" Saturatioin=\"\" Hue=\"\" />\n")
		   + sizeof(char)*4;
#else
	pos += strlen(pos);
#endif
    pos = memcpy(pos, END_MESSAGE, strlen(END_MESSAGE));
	pos += strlen(END_MESSAGE);

    len = pos - buffer;
    hdr = InitVSP_RECVHeader(len-sizeof(hdr), VIDEO_PARA_GETTING_RES, 0, 0);
    memcpy(buffer, &hdr, sizeof(hdr));
    if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
    {
	    LOGERROR("SendDataFunc error!\n");
    }
	return;
}

void SendVideoParaPicDetect(int fd)
{
	int sockfd = fd, len = 0, num = 0, i = 0;
	char buffer[512], *pos = NULL;
	VSP_RECVHEADER hdr;

	pos = buffer + sizeof(hdr);
    pos = memcpy(pos, XMLHEADER, strlen(XMLHEADER));
	pos += strlen(XMLHEADER);
    pos = memcpy(pos, START_MESSAGE, strlen(START_MESSAGE));
	pos += strlen(START_MESSAGE);
	len = strlen("<Para>8</Para>\n");
	pos = memcpy(pos, "<Para>8</Para>\n", len);
	pos += len;
    num = global_config->dev_codec_param.codec_param[0].hideZone.maxnum;
	sprintf(pos, "<Record bDetecting=\"%d\" DetectGrade=\"%d\" Num=\"%d\" >\n",
		   global_config->dev_codec_param.codec_param[0].picDetect.bDetecting,
		   global_config->dev_codec_param.codec_param[0].picDetect.detectGrade,
		   num);
#if 0
	pos += strlen("<Record bDetecting=\"\" DetectGrade=\"\" Num=\"\" >\n")
		   + sizeof(char)*3;
#else
	pos += strlen(pos);
#endif
    for(;i < num; i++)
	{
        sprintf(pos, "<Rect Left=\"%d\" Top=\"%d\" Width=\"%d\" Height=\"%d\" />\n",
			   (global_config->dev_codec_param.codec_param[0].hideZone.rect[i].left[0] |
				(global_config->dev_codec_param.codec_param[0].hideZone.rect[i].left[1]<<8)),
			   (global_config->dev_codec_param.codec_param[0].hideZone.rect[i].top[0] |
				(global_config->dev_codec_param.codec_param[0].hideZone.rect[i].top[1]<<8)),
			   (global_config->dev_codec_param.codec_param[0].hideZone.rect[i].width[0] |
				(global_config->dev_codec_param.codec_param[0].hideZone.rect[i].width[1]<<8)),
			   (global_config->dev_codec_param.codec_param[0].hideZone.rect[i].height[0] |
				(global_config->dev_codec_param.codec_param[0].hideZone.rect[i].height[1]<<8)));
#if 0
		pos += strlen("<Rect Left=\"\" Top=\"\" Width=\"\" Height=\"\" />\n") +
			   sizeof(char)*4;
#else
		pos += strlen(pos);
#endif
	}
	pos = memcpy(pos, "</Record>\n", strlen("</Record>\n"));
	pos += strlen("</Record>\n");
    pos = memcpy(pos, END_MESSAGE, strlen(END_MESSAGE));
	pos += strlen(END_MESSAGE);

    len = pos - buffer;
    hdr = InitVSP_RECVHeader(len-sizeof(hdr), VIDEO_PARA_GETTING_RES, 0, 0);
    memcpy(buffer, &hdr, sizeof(hdr));
    if(SendDataFunc(buffer, len, len, NULL, sockfd) == -1)
    {
	    LOGERROR("SendDataFunc error!\n");
    }
	return;
}

